<?php

namespace app\organization\controller\organization;

use app\common\controller\Frontend;
use app\common\model\banxi\organization\OrganizationQuotaRw as OrganizationQuotaRwModel;
use app\common\service\ExportService;
use think\db\exception\DbException;

/**
 * 机构
 */
class OrganizationQuotaRw extends Frontend
{
    protected array $noNeedLogin = [];

    protected array $noNeedPermission = ['*'];

    public function initialize(): void
    {
        parent::initialize();
        $this->model = new OrganizationQuotaRwModel();
    }

    /**
     * 分页查询
     * @return void
     * @throws DbException
     */
    public function listPage(): void
    {
        $param = $this->request->param(['index', 'limit', 'orderBy', "query"]);
        $param['query']['EQ_organizationId'] = $this->auth->organizationId;
        //查询条件解析
        $where = get_query($param);
        //获取分页数据
        $pageParams = get_page_params($param);
        $list = $this->model->getListPage($where, $pageParams['page'], $pageParams['limit']);
        $this->ok('操作成功', result_row($list));
    }


    /**
     * 查询
     * @return void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function get()
    {
        $param = $this->request->param(["query" => []]);
        if (empty($param['query'])) {
            $this->fail('查询条件不能为空');
        }
        $param['query']['EQ_organizationId'] = $this->auth->organizationId;
        $where = get_query($param);
        $info = $this->model->getInfo($where);
        $this->ok('操作成功', $info);
    }

    public function exportExcel()
    {
        $param = $this->request->param(['index', 'limit', 'orderBy', "query"]);
        $param['query']['EQ_organizationId'] = $this->auth->organizationId;
        //查询条件解析
        $where = get_query($param);
        $list = $this->model->getExportExcel($where);
        if (!count($list)) {
            $this->fail('导出失败，没有数据');
        }
        $exportService = new ExportService();
        $exportService->organizationQuotaRwExport($list);
    }


}